#!/usr/bin/env python
#
# Shared settings (and some other junk) for the SLDT compiler
#
# Author:   Mike Murphy <mamurph@cs.clemson.edu>
# Revision: 7 January 2009
#
# Copyright 2008-2009 Clemson University
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# This material is based upon work supported under a National Science
# Foundation Graduate Research Fellowship. Any opinions, findings,
# conclusions or recommendations expressed in this publication are those of
# the author(s) and do not necessarily reflect the views of the National
# Science Foundation.


# Base class for all custom exceptions
class CompilerException(Exception):
   def __init__(self, message, line = None):
      Exception.__init__(self, message)
      self.message = message
      self.line = line
#


# Delimiters used by this LISP dialect. For SLDT, these are regular
# parentheses, but adaptations for other dialects might want to use other
# symbols.
LEFT_DELIMITER = '('
RIGHT_DELIMITER = ')'


# Scanner token types. Note that the scanner should NEVER generate an
# UNKNOWN token, as that implies a bug in the scanner.
SCAN_TYPES = {  'UNKNOWN': 'unknown: BUG!',
                'INT':     'integer',
                'LDELIM':  'left_delimiter',
                'RDELIM':  'right_delimiter',
                'OPER':    'operator',
                'NAME':    'identifier',
                'EOF':     'end_of_file',
                'CTRL':    'control_token',
             }
#


# "List" of SLDT operators. This is actually a dictionary that maps:
# operator : (min-args, max-args, stack-output, local-usage)
#     local-usage accounts for any extra temporary stuff the operator puts
#     on the stack
OPERATOR_LIST = { '+' : (1, 2, 1, 0),
                  '-' : (1, 2, 1, 0),
                  '*' : (2, 2, 1, 0),
                  '/' : (2, 2, 1, 0),
                  '%' : (2, 2, 1, 0),
                  '<' : (2, 2, 1, 0),
                  '<=' : (2, 2, 1, 0),
                  '>' : (2, 2, 1, 0),
                  '>=' : (2, 2, 1, 0),
                  '=' : (2, 2, 1, 0),
                  '!=' : (2, 2, 1, 0),
                  '!' : (1, 1, 1, 1),
                  'if' : (3, 3, 1, 0),
                }
#


# Symbol table preloading
PRELOADED_SYMBOLS = { 'TRUE'  : 42,
                      'FALSE' : 0,
                    }
#
